package com.wuhen.sql;

import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;

import org.litepal.crud.DataSupport;

import java.util.ArrayList;
import java.util.List;

public class RecyclerViewActivity extends BaseActivity {
    private RecyclerView mRvMain;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_recycler_view);
        mRvMain = findViewById(R.id.rw_main);
        mRvMain.setLayoutManager(new LinearLayoutManager(this));
        List<User> users = DataSupport.findAll(User.class);
        List <User> data = new ArrayList<>();
        for (User user : users) {
            User user1=new User();
            user1.setId(user.getId());
            user1.setUserName(user.getUserName());
            user1.setUserPwd(user.getUserPwd());
            data.add(user1);
        }
        mRvMain.setAdapter(new UserAdapter(RecyclerViewActivity.this,data));
    }
}
